<?php
namespace app\common\repositories\system;
use app\common\repositories\BaseRepository;
use app\common\dao\system\OptionDao as dao;
/**
 * @mixin dao
 */
class OptionRepository extends BaseRepository
{
    public function __construct(dao $dao)
    {
        $this->dao = $dao;
    }

    public function getOption($type)
    {
        $data = $this->dao->getSearch()->where('type',$type)->find();
        return $data ? $data['value'] : '';
    }

    public function setOption($type,$value,$desc = '')
    {
        $data = $this->dao->getSearch()->where('type',$type)->find();
        if($data){
            $data->save(['value'=>$value]);
        }else{
            $this->dao->create(compact('type','value','desc'));
        }
    }
}